package ink.xiaobaibai.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ink.xiaobaibai.bo.MonthlyOrderHaveCodeBo;
import ink.xiaobaibai.bo.SelectMonOrderBo;
import ink.xiaobaibai.entity.Logistics;
import ink.xiaobaibai.entity.MonthlyfeeOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xiaobaibai
 * @since 2021-05-21
 */
public interface MonthlyfeeOrderDao extends BaseMapper<MonthlyfeeOrder> {

    public List<MonthlyfeeOrder> getOrderList(@Param("selectMonOrderBo") SelectMonOrderBo selectMonOrderBo);

    public Integer getCountByOrderList(@Param("selectMonOrderBo") SelectMonOrderBo selectMonOrderBo);

    @Select("SELECT cl.*,oz.`device_code` FROM monthlyfee_order cl LEFT JOIN monthlyfee_device oz ON oz.id=cl.`device_id` WHERE cl.`admin_user_id`=#{adminUserId} AND cl.create_time BETWEEN #{startTime} AND #{endTime} ORDER BY cl.create_time ASC")
    List<MonthlyOrderHaveCodeBo> getOrderBoListByAdminUserId(@Param("adminUserId") Integer userId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT cl.*,oz.`device_code` FROM monthlyfee_order cl LEFT JOIN monthlyfee_device oz ON oz.id=cl.`device_id` WHERE cl.`admin_dep_id`=#{depId} AND cl.create_time BETWEEN #{startTime} AND #{endTime} ORDER BY cl.create_time ASC")
    List<MonthlyOrderHaveCodeBo> getOrderBoListByDepId(@Param("depId") Integer depId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT * FROM logistics WHERE monthly_order_id IN (SELECT order_id FROM monthlyfee_order WHERE `status` = 'activated') AND send = 0 limit #{limitStart},#{limitEnd}")
    List<Logistics> getLogisticsListByNoSend(@Param("limitStart") Integer limitStart, @Param("limitEnd") Integer limitEnd);

    @Select("SELECT count(*) FROM logistics WHERE monthly_order_id IN (SELECT order_id FROM monthlyfee_order WHERE `status` = 'activated') AND send = 0")
    Integer getLogisticsListByNoSendCount();

}
